////////////////////////////////////////////////////////////////////////////////
// Copyright 2006 CORE Solutions Limited
// All rights reserved.
// PROPRIETARY AND CONFIDENTIAL INFORMATION.
// Use is subject to license terms.
//
// FUNCTION ID      :   
// AUTHOR           :   
// DATE CREATE      :   
// DESCRIPTION      :   
//                  :   
//                  :   
//                  :   
//
// MODIFICATION HISTORY:
// DATE         AUTHOR          VERSION NO.         COMMENT
// -----------  --------------  ------------------  -------------------
// 2006/05/17   Ric Yik         1.0                 BugZilla #5796
//
//
//
////////////////////////////////////////////////////////////////////////////////
package com.erp.framework.controller.action;

import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.erp.app.admin.sysParam.beans.SysParamList;
import com.erp.app.common.ProjectConstants;
import com.erp.app.util.web.WebUtil;
import com.erp.framework.SimpleConstants;
import com.erp.framework.controller.form.SimpleSearchStyleForm;
import com.erp.framework.model.criteria.SimpleBaseSrchCriteria;
import com.erp.framework.model.delegate.SimpleSearchMaintStyleDelegate;
import com.erp.framework.model.pk.SimpleBasePk;
import com.erp.framework.model.vo.SimpleBaseVo;
import com.erp.framework.util.BeanUtil;
import com.erp.framework.util.CommonUtil;
import com.erp.framework.util.CopyUtil;
import com.erp.framework.util.logger.Logger;
import com.erp.framework.util.user.User;

public abstract class SimpleSearchStyleAction extends SimpleCoreAction {

    ////////////////////////////////////////////////////////////////////////////////
    // ABSTRACT METHODS THAT NEED BE IMPLEMENTED BY SUB-CLASSES
    ////////////////////////////////////////////////////////////////////////////////

    protected abstract String getModuleName(ActionMapping mapping, ActionForm formIn, HttpServletRequest request,
            HttpServletResponse response);

    protected abstract String getFunctionId();
       
    protected abstract String getMasterFormSessionName();
        
    protected abstract Class getMasterFormClass();
    
    protected abstract Class getMasterVOClass();
    
    protected abstract Class getSearchCriteriaClass();
        
    protected abstract void setOtherCriteria(ActionMapping mapping, ActionForm formIn, HttpServletRequest request,
            HttpServletResponse response, ActionErrors errors, Object criteria);
    
    protected abstract SimpleBasePk getPk(ActionMapping mapping, ActionForm formIn, HttpServletRequest request,
            HttpServletResponse response, ActionErrors errors);    

    protected abstract void setFormType(ActionMapping mapping, ActionForm formIn, HttpServletRequest request,
            HttpServletResponse response, ActionErrors errors);
    
    ////////////////////////////////////////////////////////////////////////////////
    // END OF ABSTRACT METHODS
    ////////////////////////////////////////////////////////////////////////////////

    
    ////////////////////////////////////////////////////////////////////////////////
    // OPTIONAL METHODS THAT CAN BE OVERWRITTEN BY SUB-CLASSES
    ////////////////////////////////////////////////////////////////////////////////

    //the following method is only to be overwritten by sub-class if intended
    //to set the aut-search on-load to on/off
    protected boolean getLoadOnEnter() {

        //auto-search when load
        return true;
    }

    //the following method is only to be overwritten by sub-class if intended
    //to set the clearing search result sets on-load to on/off
    protected boolean getResetOnEnter() {

        //reset last searched results when load 
        return true;
    }
    
	//old way
    /**
     * @ddeprecated
     */
    protected void initAction(ActionMapping mapping, ActionForm formIn, HttpServletRequest request, HttpServletResponse response) {

    }

    protected void initAction(ActionMapping mapping, ActionForm formIn, HttpServletRequest request, HttpServletResponse response,
            ActionErrors errors) {
    	
    	
    }
    
    protected void initForm(ActionMapping mapping, ActionForm formIn, HttpServletRequest request,
            HttpServletResponse response, ActionErrors errors) {

        SimpleSearchStyleForm form = (SimpleSearchStyleForm) formIn;
        HttpSession session = request.getSession(false);
        ActionForward actionForward = new ActionForward(mapping.getInput());

        String reset = GENERIC_YES;
        if (!getResetOnEnter()) {
            reset = CommonUtil.nullToString((String) session.getAttribute(getSessionReset()));
            session.removeAttribute(getSessionReset());
        }

        if (reset.equalsIgnoreCase(GENERIC_YES)) {
            form.resetForm();
        }

        initPage(mapping, formIn, request, response, errors);
    }
    
    protected void initPage(ActionMapping mapping, ActionForm formIn, HttpServletRequest request, HttpServletResponse response,
            ActionErrors errors) {
    }

    protected void beforeEdit(ActionMapping mapping, ActionForm formIn, HttpServletRequest request, HttpServletResponse response,
            ActionErrors errors) {

    }

    protected void afterEdit(ActionMapping mapping, ActionForm formIn, HttpServletRequest request, HttpServletResponse response,
            ActionErrors errors) {

    }
    
    protected void beforeSearch(ActionMapping mapping, ActionForm formIn, HttpServletRequest request, HttpServletResponse response,
            ActionErrors errors) {

    }

    protected void afterSearch(ActionMapping mapping, ActionForm formIn, HttpServletRequest request, HttpServletResponse response,
            ActionErrors errors) {

    }
    
    protected Class getMasterDelegateClass() {

        return SimpleSearchMaintStyleDelegate.class;
    }

    protected Class getCopyActionClass() {

        return null;
    }
    
    protected String getSessionMasterDelegate() {

        return "MASTER_DELEGATE";
    }

    protected String getSessionSimpleSearchStatus() {

        return SimpleConstants.SESSION_SIMPLE_SEARCH_STATUS;
    }

    protected String getSessionSimpleMaintStatus() {

        return SimpleConstants.SESSION_SIMPLE_MAINT_STATUS;
    }
    
    protected String getSessionSimpleMaintPk() {

        return SimpleConstants.SESSION_SIMPLE_MAINT_PK;
    }

    protected String getSessionSimpleMaintInitModel() {

        return SimpleConstants.SESSION_SIMPLE_MAINT_INIT_MODEL;
    }
    
    protected String getSessionSimpleMaintEditType() {

        return SimpleConstants.SESSION_SIMPLE_MAINT_EDIT_TYPE;
    }
    
    protected String getSessionReset() {

        return SimpleConstants.SESSION_SIMPLE_SEARCH_RESET;
    }
    
    protected SimpleBaseVo getInitialzedModel(ActionForm form, User editingUser) {

        return null;
    }
    
    protected Class getMasterVOClass(ActionForm form) {
        return getMasterVOClass();
    }
    
    ////////////////////////////////////////////////////////////////////////////////
    // END OF OPTIONAL METHODS
    ////////////////////////////////////////////////////////////////////////////////

    
    ////////////////////////////////////////////////////////////////////////////////
    // LOGICAL AND BUSINESS METHODS
    ////////////////////////////////////////////////////////////////////////////////

    protected ActionForward handlePageEvent(ActionMapping mapping, ActionForm formIn, HttpServletRequest request,
            HttpServletResponse response, ActionErrors errors) {

        ActionForward actionForward = new ActionForward(mapping.getInput());
        return actionForward;
    }
    
    protected ActionForward processOtherStatus(ActionMapping mapping, ActionForm formIn, HttpServletRequest request,
            HttpServletResponse response, ActionErrors errors, String rb_status) {

        ActionForward actionForward = new ActionForward(mapping.getInput());

        return actionForward;
    }
    
    public ActionForward otherExecute(ActionMapping mapping, ActionForm formIn, HttpServletRequest request,
            HttpServletResponse response) throws ServletException {

        ActionForward actionForward = null;
        try {
            HttpSession session = request.getSession(false);
            ActionErrors errors = new CustomActionErrors(new ActionErrors());
            SimpleSearchStyleForm form = (SimpleSearchStyleForm) formIn;
            String action = form.getPageEvent();

            action = CommonUtil.isEmpty(action) ? "" : action.trim();
            actionForward = new ActionForward(mapping.getInput());

            String rb_status = CommonUtil.nullToString((String) session.getAttribute(getSessionSimpleSearchStatus()));
            session.removeAttribute(getSessionSimpleSearchStatus());

            Logger.debug(this, "action = " + action + ", mode = " + form.getPageMode() + ", rb_status=[" + rb_status + "]");
            Logger.debug(this, "isHandled=" + isHandled(request));

            initAction(mapping, formIn, request, response);
            initAction(mapping, formIn, request, response, errors);

            setFormType(mapping, form, request, response, errors);
            
            if (!isHandled(request) && !rb_status.equals("")) {
                setHandled(request);
                actionForward = processStatus(mapping, formIn, request, response, errors, rb_status);
            }

            // for initial status
            if (!isHandled(request) && action.length() == 0) {
                setHandled(request);
                initForm(mapping, formIn, request, response, errors);
                if (getLoadOnEnter()) {
                    action = ACTION_SEARCH;
                    resetHandled(request);
                } else {
                    initPage(mapping, form, request, response, errors); // new way
                }
            }

            try{
            // Sets the TableSchema
                super.copyTsFromVoToForm(mapping, formIn, request, response, null); 
                session.setAttribute(getMasterFormSessionName(), formIn);
            } catch(Exception e){
                Logger.logExceptions(this, e);
            }
            
            if (!isHandled(request) && action.equalsIgnoreCase(ACTION_SEARCH)) {
                setHandled(request);
                actionForward = processActionSearch(mapping, formIn, request, response, errors);
                saveToken(request);
            } else if (!isHandled(request) && action.equalsIgnoreCase(ACTION_EDIT)) {
                setHandled(request);
                actionForward = processActionEdit(mapping, formIn, request, response, errors);
                saveToken(request);
            } else if (!isHandled(request) && action.equalsIgnoreCase(ACTION_CREATE)) {
                setHandled(request);
                actionForward = processActionCreate(mapping, formIn, request, response, errors);
                saveToken(request);
            } else if (!isHandled(request) && action.equalsIgnoreCase(ACTION_EXIT)) {
                setHandled(request);
                actionForward = processActionExit(mapping, formIn, request, response, errors);
                saveToken(request);
            } else if (!isHandled(request) && action.equalsIgnoreCase(ACTION_SCROLL_LEFT)) {
                setHandled(request);
                actionForward = processActionScrollLeft(mapping, formIn, request, response, errors);
                saveToken(request);
            } else if (!isHandled(request) && action.equalsIgnoreCase(ACTION_SCROLL_RIGHT)) {
                setHandled(request);
                actionForward = processActionScrollRight(mapping, formIn, request, response, errors);
                saveToken(request);
            } else if (!isHandled(request) && action.equalsIgnoreCase(ACTION_SCROLL_TO_FIRST_PAGE)) {
                setHandled(request);
                actionForward = processActionScrollToFirstPage(mapping, formIn, request, response, errors);
                saveToken(request);
            } else if (!isHandled(request) && action.equalsIgnoreCase(ACTION_SCROLL_TO_LAST_PAGE)) {
                setHandled(request);
                actionForward = processActionScrollToLastPage(mapping, formIn, request, response, errors);
                saveToken(request);
            } else if (!isHandled(request) && action.equalsIgnoreCase(ACTION_SCROLL_TO)) {
                setHandled(request);
                actionForward = processActionScrollTo(mapping, formIn, request, response, errors);
                saveToken(request);
            } else if (!isHandled(request) && action.equalsIgnoreCase(ACTION_CANCEL)) {
                actionForward = processActionCancel(mapping, formIn, request, response, errors);
                setHandled(request);
            } else if (!isHandled(request) && action.equalsIgnoreCase(ACTION_CLEAR)) {
                actionForward = processActionClear(mapping, formIn, request, response, errors);
                setHandled(request);
                saveToken(request);
            } else if (!isHandled(request) && action.equalsIgnoreCase(ACTION_COPY)) {
                setHandled(request);
                actionForward = processActionCopy(mapping, formIn, request, response, errors);
            } else if (!isHandled(request) && action.length() > 0) {
                actionForward = handlePageEvent(mapping, formIn, request, response, errors);
                setHandled(request);
            }
            saveErrors(request, errors);
        } catch (Exception e) {
            Logger.logExceptions(this, e);
        }
        return actionForward;
    }
    
    protected ActionForward processStatus(ActionMapping mapping, ActionForm formIn, HttpServletRequest request,
            HttpServletResponse response, ActionErrors errors, String rb_status) {

        ActionForward actionForward = new ActionForward(mapping.getInput());

        if (rb_status.equalsIgnoreCase(STATUS_COPY)) {
            return processStatusCopy(mapping, formIn, request, response, errors, rb_status);
        } else {
            return processOtherStatus(mapping, formIn, request, response, errors, rb_status);
        }
    }
    
    protected ActionForward processActionSearch(ActionMapping mapping, ActionForm formIn, HttpServletRequest request,
            HttpServletResponse response, ActionErrors errors) {

        ActionForward actionForward = null;
        try {
            SimpleSearchStyleForm form = (SimpleSearchStyleForm) formIn;
            HttpSession session = request.getSession(false);
            try {
                if (CommonUtil.isEmpty(BeanUtil.getPropertyDefault(form, "srchCompanyCode"))) {
                    BeanUtil.setPropertyDefault(form, "srchCompanyCode", WebUtil.getAppropriateCompanyCode(session, null));
                }
            } catch (Exception e) {
                Logger.debug(this, e);
            }
            beforeSearch(mapping, form, request, response, errors);

            actionForward = new ActionForward(mapping.getInput());

            form.clearResultList();            
            form.validateSearch(errors);
            form.moreValidateSearch(mapping, formIn, request, response, errors);
            
            if (errors.size() == 0) {
                SimpleSearchMaintStyleDelegate dg = getMasterDelegate(session);
                SimpleBaseVo model = (SimpleBaseVo) getMasterVOClass(formIn).newInstance();
                //SimpleBaseVo model = (SimpleBaseVo) getMasterVOClass().newInstance();
                Object criteria = setCriteria(mapping, formIn, request, response, errors);
                ArrayList srchRslt = (ArrayList) dg.findByCriteria(model, criteria);
                form.setResultList(srchRslt);
                initPage(mapping, form, request, response, errors); // new way
                if (srchRslt == null || srchRslt.size() == 0) {
                    errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("warning.no_record_found"));
                }
            }
            
            afterSearch(mapping, form, request, response, errors);
        } catch (Exception e) {
            errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("exception.general", e.toString()));
            Logger.logExceptions(this, e);
        }

        return actionForward;
    }

    protected ActionForward processActionEdit(ActionMapping mapping, ActionForm formIn, HttpServletRequest request,
            HttpServletResponse response, ActionErrors errors) {

        ActionForward actionForward = null;
        try {
            SimpleSearchStyleForm form = (SimpleSearchStyleForm) formIn;
            
            beforeEdit(mapping, form, request, response, errors);
            
            HttpSession session = request.getSession(false);
            actionForward = new ActionForward(mapping.getInput());

            SimpleBasePk pk = getPk(mapping, formIn, request, response, errors);
            if (pk != null) {
                session.setAttribute(getSessionSimpleMaintStatus(), "edit");
                session.setAttribute(getSessionSimpleMaintPk(), pk);
                session.setAttribute(getSessionSimpleMaintEditType(), form.getEditType());
                actionForward = mapping.findForward("edit");
            }
            
            afterEdit(mapping, form, request, response, errors);
        } catch (Exception e) {
            errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("exception.general", e.toString()));
            Logger.logExceptions(this, e);
        }
        return actionForward;
    }

    protected ActionForward processActionCreate(ActionMapping mapping, ActionForm formIn, HttpServletRequest request,
            HttpServletResponse response, ActionErrors errors) {

        ActionForward actionForward = null;
        try {
            SimpleSearchStyleForm form = (SimpleSearchStyleForm) formIn;
            HttpSession session = request.getSession(false);

            actionForward = new ActionForward(mapping.getInput());

            User editingUser = (User) session.getAttribute(SimpleConstants.SESSION_USER);

            SimpleBaseVo model = getInitialzedModel(form, editingUser);
            if (model != null) {
                session.setAttribute(getSessionSimpleMaintInitModel(), model);
            }
            session.setAttribute(getSessionSimpleMaintStatus(), "create");
            session.setAttribute(getSessionSimpleMaintEditType(), form.getEditType());
            actionForward = mapping.findForward("edit");
        } catch (Exception e) {
            errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("exception.general", e.toString()));
            Logger.logExceptions(this, e);
        }
        return actionForward;
    }

    protected ActionForward processActionExit(ActionMapping mapping, ActionForm formIn, HttpServletRequest request,
            HttpServletResponse response, ActionErrors errors) {

        ActionForward actionForward = null;
        try {
            HttpSession session = request.getSession(false);
            actionForward = new ActionForward(mapping.getInput());
            session.removeAttribute(getMasterFormSessionName());
            removeMasterDelegate(session);
            actionForward = mapping.findForward("default");
        } catch (Exception e) {
            errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("exception.general", e.toString()));
            Logger.logExceptions(this, e);
        }
        return actionForward;
    }

    protected ActionForward processActionScrollLeft(ActionMapping mapping, ActionForm formIn, HttpServletRequest request,
            HttpServletResponse response, ActionErrors errors) {

        ActionForward actionForward = null;
        try {
            SimpleSearchStyleForm form = (SimpleSearchStyleForm) formIn;
            actionForward = new ActionForward(mapping.getInput());
            int sidx = form.getSidx();
            sidx -= SimpleConstants.MAX_DISPLAY;

            if (sidx < 0)
                sidx = 0;
            if (sidx > form.getResultList().size() - 1)
                sidx = form.getResultList().size() - 1;

            form.setSidx(sidx);
        } catch (Exception e) {
            errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("exception.general", e.toString()));
            Logger.logExceptions(this, e);
        }
        return actionForward;
    }

    protected ActionForward processActionScrollRight(ActionMapping mapping, ActionForm formIn, HttpServletRequest request,
            HttpServletResponse response, ActionErrors errors) {

        ActionForward actionForward = null;
        try {
            SimpleSearchStyleForm form = (SimpleSearchStyleForm) formIn;
            actionForward = new ActionForward(mapping.getInput());

            int sidx = form.getSidx();

            sidx += SimpleConstants.MAX_DISPLAY;

            if (sidx < 0)
                sidx = 0;
            if (sidx > form.getResultList().size() - 1)
                sidx = form.getResultList().size() - 1;

            form.setSidx(sidx);
        } catch (Exception e) {
            errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("exception.general", e.toString()));
            Logger.logExceptions(this, e);
        }
        return actionForward;
    }

    protected ActionForward processActionScrollToFirstPage(ActionMapping mapping, ActionForm formIn, HttpServletRequest request,
            HttpServletResponse response, ActionErrors errors) {
        ActionForward actionForward = new ActionForward(mapping.getInput());
        SimpleSearchStyleForm form = (SimpleSearchStyleForm) formIn;

        form.setSidx(0);

        return actionForward;
    }

    protected ActionForward processActionScrollToLastPage(ActionMapping mapping, ActionForm formIn, HttpServletRequest request,
            HttpServletResponse response, ActionErrors errors) {
        ActionForward actionForward = new ActionForward(mapping.getInput());
        SimpleSearchStyleForm form = (SimpleSearchStyleForm) formIn;

        form.setSidx(Integer.parseInt(form.getLastPageSidx()));

        return actionForward;
    }

    protected ActionForward processActionScrollTo(ActionMapping mapping, ActionForm formIn, HttpServletRequest request,
            HttpServletResponse response, ActionErrors errors) {
        ActionForward actionForward = new ActionForward(mapping.getInput());
        SimpleSearchStyleForm form = (SimpleSearchStyleForm) formIn;

        String scrollTo = form.getScrollTo();
        int page = 0;

        try {
            page = Integer.parseInt(scrollTo);
        } catch (NumberFormatException e) {
            page = form.getCurrentPage();
        }

        if (page < 1)
            page = 1;

        if (page > form.getTotalPage())
            page = form.getTotalPage();

        form.setSidx((page - 1) * ProjectConstants.MAX_DISPLAY);

        return actionForward;
    }

    protected ActionForward processActionCancel(ActionMapping mapping, ActionForm formIn, HttpServletRequest request,
            HttpServletResponse response, ActionErrors errors) {

        return mapping.findForward("default");
    }

    protected ActionForward processActionClear(ActionMapping mapping, ActionForm formIn, HttpServletRequest request,
            HttpServletResponse response, ActionErrors errors) {

        SimpleSearchStyleForm form = (SimpleSearchStyleForm) formIn;
        ActionForward actionForward = new ActionForward(mapping.getInput());

        form.resetForm();
        return actionForward;
    }
    
    protected ActionForward processActionCopy(ActionMapping mapping, ActionForm formIn, HttpServletRequest request,
            HttpServletResponse response, ActionErrors errors) {

        ActionForward actionForward = new ActionForward(mapping.getInput());
        try {
            SimpleCopyAction copyAction = (SimpleCopyAction) getCopyActionClass().newInstance();
            String sessionName = getSessionSimpleSearchStatus();
            String sessionValue = STATUS_COPY;
            String exclusive = GENERIC_YES;
            String opener = getFunctionId();
            copyAction.showCopyDialog(request, sessionName, sessionValue, exclusive, opener);
        } catch (Exception e) {
            Logger.logExceptions(this, e);
            errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("exception.general", e.toString()));
        }

        return actionForward;
    }

    protected ActionForward processStatusCopy(ActionMapping mapping, ActionForm formIn, HttpServletRequest request,
            HttpServletResponse response, ActionErrors errors, String rb_status) {

        try {
            HttpSession session = request.getSession(false);
            ActionForward actionForward = new ActionForward(mapping.getInput());
            session.setAttribute(getSessionSimpleMaintStatus(), STATUS_COPY);
            actionForward = mapping.findForward("edit");

            return actionForward;
        } catch (Exception e) {
            errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("exception.general", e.toString()));
            Logger.logExceptions(this, e);
            return null;
        }
    }
    
    protected Object setCriteria(ActionMapping mapping, ActionForm formIn, HttpServletRequest request,
            HttpServletResponse response, ActionErrors errors) {

        Object criteria = null;
        try {
            SimpleSearchStyleForm form = (SimpleSearchStyleForm) formIn;
            criteria = getSearchCriteriaClass().newInstance();
            CopyUtil.cpNconv(criteria, form);

            if (isPerformStrEscaping())
                BeanUtil.escapeSearchStrings(criteria);

            HttpSession session = request.getSession(false);
            SysParamList list = (SysParamList) session.getAttribute(ProjectConstants.SESSION_SYS_PARAM);
            User editingUser = (User) session.getAttribute(SimpleConstants.SESSION_USER);
            ((SimpleBaseSrchCriteria) criteria).setSysParamList(list);
            ((SimpleBaseSrchCriteria) criteria).setLoginCompanyCode(editingUser.getCompanyCode());
            ((SimpleBaseSrchCriteria) criteria).setSrchUser(editingUser);

            // user data access security
            ArrayList userDataAccessInfo = (ArrayList) session.getAttribute(ProjectConstants.SESSION_USER_DATA_ACCESS_SECURITY);
            if (userDataAccessInfo != null) {
                ((SimpleBaseSrchCriteria) criteria).setUserSecurityList(userDataAccessInfo);
            }

            setOtherCriteria(mapping, formIn, request, response, errors, criteria);
        } catch (Exception e) {
            Logger.logExceptions(this, e);
        }

        return criteria;
    }
    
    protected SimpleSearchMaintStyleDelegate getMasterDelegate(HttpSession session) {

        try {
            if (session.getAttribute(getSessionMasterDelegate()) != null) {
                return (SimpleSearchMaintStyleDelegate) session.getAttribute(getSessionMasterDelegate());
            } else {
                SimpleSearchMaintStyleDelegate dg = new SimpleSearchMaintStyleDelegate();
                session.setAttribute(getSessionMasterDelegate(), dg);
                return dg;
            }
        } catch (Exception e) {
            Logger.logExceptions(this, e);
        }
        return null;
    }

    protected void removeMasterDelegate(HttpSession session) {

        try {
            getMasterDelegate(session).removeSessionBean();
            session.removeAttribute(getSessionMasterDelegate());
        } catch (Exception e) {
            Logger.logExceptions(this, e);
        }
    }

    protected boolean hasAccessRight(String menuId, User editingUser) {

        boolean hasRight = true;
        return hasRight;
    }
    
    protected boolean isPerformStrEscaping() {
        return true;
    }
    
    protected boolean checkIfFormExists(SimpleBasePk pk, ActionErrors errors) throws Exception {

        boolean rslt = false;

        SimpleSearchMaintStyleDelegate dg = (SimpleSearchMaintStyleDelegate) getMasterDelegateClass().newInstance();
        try {
            rslt = dg.checkIfFormExists(pk);
        } catch (Exception e) {
            errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("exception.general", e.toString()));
            Logger.logExceptions(this, e);
        }
        return rslt;
    }
    
    protected void afterExecuteAction(ActionMapping mapping, ActionForm formIn, HttpServletRequest request, HttpServletResponse response) {
    	SimpleSearchStyleForm form = (SimpleSearchStyleForm) formIn;
  	  	HttpSession session = request.getSession(false);
		try {
			BeanUtil.setPropertyDefault(form, "srchCompanyCode", WebUtil.getAppropriateCompanyCode(session));
		} catch (Exception e) {
            Logger.debug(this, "Cant't find srchCompanyCode");
		}  	  	
		super.afterExecuteAction(mapping, formIn, request, response);
   	 }

    
    ////////////////////////////////////////////////////////////////////////////////
    // END OF LOGICAL AND BUSINESS METHODS
    ////////////////////////////////////////////////////////////////////////////////
}